package de.cau.apo.problems.travellingsalesman;

import java.util.HashMap;
import java.util.Map;

/**
 * This class represents a node for the traveling salesman problem.
 * It just consists of an fixed index and of a map of costs to the neighbor nodes.
 * 
 * @author Marius Richter
 *
 */
public class Node {

	// ########### properties ###########
	
	/** the index of this node */
	public final int index;
	/** a map of costs with the to node as the key and the cost as the value */
	public final Map<Integer,Integer> edges = new HashMap<Integer,Integer>();
	
	// ########### instantiation ###########
	
	/**
	 * Create new node.
	 * @param index the index of this node
	 */
	public Node(int index) {
		this.index = index;
	}
	
	// ########### getter/setter ###########
	
	/**
	 * @return the index of this node
	 */
	public int getIndex() {
		return index;
	}
	
	/**
	 * @param to the node that shall be the destination of the edge
	 * @return the cost from this node to the given to-node
	 */
	public int getEdgeCost(Node to) {
		Integer cost = edges.get(to.getIndex());
		if (cost == null) {
			return 0;
		}
		return cost;
	}

	// ########### overriding toString() ###########
	
	@Override
	public String toString() {
		return "Node [index=" + index + ",edges=" + edges + "]";
	}
	
}
